#include <iostream>
using namespace std;

int main() {
    int N = 0;
    cin >> N;
    if(N == 1 || N == 0)
    {
        cout << 0 << endl;
        return 0;
    }

    int n1 = 0;
    int n2 = 1;
    int n3 = 0;
    while(1)
    {
        // 假设 N = 15
        // 0  1  1  2  3  5  8  13  21  34
        //                   n1 n2  n3
        n3 = n1 + n2;
        if(n3 >= N)
        {
            int ret = (n3 - N) >= (N - n2) ? N - n2 : n3 - N;
            cout << ret << endl;
            return 0;
        }
        n1 = n2;
        n2 = n3;
    }
}